local Lua__bayou = fk.CreateSkill {

  name = "Lua__bayou",
}

Fk:loadTranslationTable{
    ["Lua__bayou"] = "霸油",
    [":Lua__bayou"] = "当你受到其他角色造成的伤害后，你可以摸至多两张牌并令其获得X枚“油田”标记（X为2-你摸的牌数）。有“油田”标记的角色：获得牌后，你可移去其一枚“油田”标记并获得其一张牌；受到伤害时，你可移去其所有“油田”标记（至少两枚），令此伤害+1且改为火焰伤害。",
    ["#bayou-draw"] = "霸油：选择摸牌数（0-2）",
    ["@oil"] = "油田",
}

Lua__bayou:addEffect(fk.Damaged, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if player:hasSkill(Lua__bayou.name)  then
            return target == player and data.from and data.from ~= player
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local choices = {"Cancel","0","1","2"}

        local choice = player.room:askToChoice(player, {
            choices = choices,
            skill_name = Lua__bayou.name,
            prompt = "#bayou-draw",
        })
        if choice ~= "Cancel" then
            event:setCostData(self, {choice = tonumber(choice)} )
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local num = event:getCostData(self).choice
        player:drawCards(num, Lua__bayou.name)
        room:addPlayerMark(data.from, "@oil", 2 - num)
       
    end,
})
Lua__bayou:addEffect(fk.AfterCardsMove, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if player:hasSkill(Lua__bayou.name)  then
            for _, move in ipairs(data) do
              if move.to and move.to ~= player and move.to:getMark("@oil") > 0 then
                return true
              end
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        return player.room:askToSkillInvoke(player, {skill_name = Lua__bayou.name})
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        for _, move in ipairs(data) do
            if move.to and move.to ~= player then
                if move.to:getMark("@oil") > 0 then
                    room:removePlayerMark(move.to, "@oil", 1)
                    if not move.to:isNude() then
                        local card = room:askToChooseCard(player, {
                            target = move.to,
                            flag = "he",
                            skill_name = Lua__bayou.name,
                        })
                        room:obtainCard(player, card, false, fk.ReasonPrey)
                    end
                end
            end
        end
    end,
})
Lua__bayou:addEffect(fk.DamageInflicted, {
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if player:hasSkill(Lua__bayou.name)  then
            return target:getMark("@oil") > 1
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        return player.room:askToSkillInvoke(player, {skill_name = Lua__bayou.name,})
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(target, "@oil", 0)
        data.damage = data.damage + 1
        data.damageType = fk.FireDamage
    end,
})

return Lua__bayou